package com.lgl.scsheader.base.controller;

import com.lgl.scsapi.system.model.PageData;
import com.lgl.scsapi.system.model.SysUser;
import com.lgl.scsapi.util.utils.Constants;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class BaseController {

	/**
	 * 得到PageData
	 */
	public PageData getPageData(){
		return new PageData(this.getRequest());
	}
	
	/**
	 * 得到request对象
	 */
	public HttpServletRequest getRequest() {
		return ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
	}

	/**
	 * 获取session中的用户
	 * @return 系统用户
	 */
	public SysUser getSessionUser() {
		Subject currentUser = SecurityUtils.getSubject();  
		Object object = currentUser.getSession().getAttribute(Constants.SESSION_USER);
		if (object != null) {
			return (SysUser) object;
		}
		return null;
	}
}